/**
 * Huisou.com Inc.
 * Copyright (c) 2011-2012 All Rights Reserved.
 */

package com.chenzehe.zdmya.action;

import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

import com.chenzehe.java.core.freemarker.HtmlPathHelp;
import com.chenzehe.java.core.orm.Page;
import com.chenzehe.java.core.orm.PageRequest;
import com.chenzehe.java.core.utils.WebUtil;
import com.chenzehe.zdmya.domain.Coupon;
import com.chenzehe.zdmya.domain.Fx;
import com.chenzehe.zdmya.domain.Jy;
import com.chenzehe.zdmya.domain.Mall;
import com.chenzehe.zdmya.service.ICouponService;
import com.chenzehe.zdmya.service.IFxService;
import com.chenzehe.zdmya.service.IJyService;
import com.chenzehe.zdmya.service.IMallService;

/**
 * @description
 * 
 * @author chenzehe
 * @email hljuczh@163.com
 * @create 2012-8-14 下午08:14:05
 */
@Controller
public class CouponAction extends BaseAction {

	@Resource
	ICouponService couponService;
	@Resource
	IFxService fxService;
	@Resource
	IJyService jyService;
	@Resource
	IMallService mallService;

	@RequestMapping(value = "/couponlist.html")
	public String malllist(HttpServletRequest request, ModelMap model) {
		int pageNo = WebUtil.getInt(request, "pageNo", 1);
		int pageSize = WebUtil.getInt(request, "pageSize", 2);
		PageRequest pageRequest = new PageRequest(pageNo, pageSize);
		pageRequest.setOrderBy("id");
		pageRequest.setOrderDir(PageRequest.Sort.DESC);
		Page<Coupon> couponlist = couponService.queryCoupons(pageRequest);
		model.addAttribute("couponlist", couponlist);
		return HtmlPathHelp.getHtmlPathFront("couponlist");
	}

	@RequestMapping(value = "/coupon.html")
	public String mall(HttpServletRequest request, ModelMap model) {
		int id = WebUtil.getInt(request, "id", 0);
		Coupon coupon = couponService.getById(id);
		Mall mall = mallService.getMallById(coupon.getMallId());
		model.addAttribute("coupon", coupon);
		model.addAttribute("mall", mall);
		List<Fx> limitFxs = fxService.queryLimitFx(12);
		List<Coupon> limitCoupons = couponService.queryLimitCoupons(10);
		List<Jy> limitJys = jyService.queryLimitJy(5);
		model.addAttribute("limitFxs", limitFxs);
		model.addAttribute("limitCoupons", limitCoupons);
		model.addAttribute("limitJys", limitJys);
		return HtmlPathHelp.getHtmlPathFront("coupon");
	}

	@RequestMapping(value = "/coupon/go.html")
	public String go(HttpServletRequest request, ModelMap model) {
		int id = WebUtil.getInt(request, "id", 0);
		String goUrl = couponService.getGoUrl(id);
		return "redirect:" + goUrl;
	}

}
